package com.wjbgn.gobang.server.user.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjbgn.gobang.server.user.convert.GameLogDoConvert;
import com.wjbgn.gobang.server.user.dto.GameLogDTO;
import com.wjbgn.gobang.server.user.entity.GameLogDO;
import com.wjbgn.gobang.server.user.service.GameLogService;
import com.wjbgn.gobang.server.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * Create Date: 2022-04-12T20:32:37.046
 *
 * @author wjbgn
 * @version 1.0
 */
@Api(tags = "")
@RestController
@RequestMapping("/gobang/game/log")
@AllArgsConstructor
public class GameLogController {

    /**
     * GameLogService
     */
    @Autowired
    private GameLogService gameLogService;

    /**
     * 新增
     *
     * @param gameLogDTO
     * @return
     */
    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody GameLogDTO gameLogDTO) {
        gameLogDTO.setCreateTime(LocalDateTimeUtil.now());
        gameLogDTO.setUpdateTime(LocalDateTimeUtil.now());
        boolean flag = gameLogService.save(GameLogDoConvert.dtoToDo(gameLogDTO));
        if (flag) {
            GameLogDO one = gameLogService.getOne(new QueryWrapper<>(new GameLogDO("3", gameLogDTO.getUsername())));
            return Result.success(one);
        }
        return Result.failed();
    }
}